package com.testDemo.atomic;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: zour
 * @date: 2023/12/5
 * @description:
 */
public class AtomicTest {
    private List<String> getList(int i) {
        List<String> re = new ArrayList<>(i);
        for (int j = 0; j < i; j++) {
            re.add(Math.random() * 20 + "");
        }
        return re;
    }

    @Test
    public void aa() {

        int i = 2, next = 0;
        int[] lens = new int[]{2, 2, 1};
        int count = 0;
        System.out.println("start ");
        do {
            System.out.println("do");
            AtomicInteger counter = new AtomicInteger();
            getList(lens[next]).forEach(row -> {
                counter.getAndIncrement();
            });
            next++;
            count = counter.get();
            System.out.println("do end count=" + count);
        } while (count == i);
        System.out.println("end");
    }
}
